<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta charset="utf-8">
    <title>人人乐信息管理系统</title>
    <link rel="stylesheet" type="text/css" href="/css/style.css"/>
    <script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
</head>

<body>
<div class="container">
    <div class="loginbox">
        <div class="loginform">
            <div class="clear" style="height:146px"></div>
            <h2>人人乐信息管理系统</h2>
            <form action="/loginsubmit" method="post">
                <table width="100%" border="0">
                    <tr>
                        <td>
                            <span>用户名</span>
                            <input class="uname" type="text" name="username" id="username" placeholder="账号"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span>密码</span>
                            <input class="pword" type="password" name="password" id="password" placeholder="密码"/>
                        </td>
                    </tr>
                    <tr>
                        <td height="80">
                            <a class="logbtn" id="loginBtn" onclick="login()">登录</a>
                        </td>
                    </tr>
                    <tr>
                        <td height="80">
                            <a class="logbtn" id="registerBtn" onclick="register()">注册</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<script src="../js/jquery-3.2.1.js"></script>
<script>
    $(function () {
        $(".loginform form td input").focus(function () {
            $(this).css("border-color", "#56c68b");
        });
        $(".loginform form td input").blur(function () {
            $(this).css("border-color", "#bdbcbc");
        });
    });

    //登录
    function login() {
        $.ajax({
            url: "/userlogin",
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            success: function (result) {
                if (result.msg === "成功") {
                    window.location.href = "/"
                } else {
                    alert("账号密码错误")
                }
            }
        })
    }

    //跳转到注册页面
    function register() {
        window.location.href = "/registerPage"
    }

</script>

</body>
</html>